Skip to content

Drop eager MCP schema preload in workerd isolates - #1742

Merged
RhysSullivan merged 1 commit into
mainfrom
fix/mcp-v2-lazy-schemas
Aug 25, 2026
Merged

Drop eager MCP schema preload in workerd isolates#1742
RhysSullivan merged 1 commit into
mainfrom
fix/mcp-v2-lazy-schemas

Conversation

@RhysSullivan

Copy link
Copy Markdown
Collaborator

Since #1733, p95 on authenticated API routes roughly doubled (2-2.5s -> 4.5-5.5s) and isolate reuse halved (~5-7 -> ~3 requests per isolate), version-correlated in traces: in the same 15-minute window the old version served p95 2.4s while #1733's deploy served 5.3s.

Mechanism: @modelcontextprotocol/client's workerd shim runs preloadSchemas() at module eval, building both protocol eras' zod schemas in every isolate. Measured under the workerd export condition: importing the barrel costs ~30MB heap upstream vs ~11MB with this patch. That ~19MB per-isolate baseline is what pressures Cloudflare into evicting isolates, collapsing reuse; every extra cold isolate then eats the first-await startup penalty on whatever authenticated request lands on it.

Fix: bun patch the package to drop the eager preload. Schema construction stays lazy and memoized (upstream's documented default on other runtimes); the first MCP use in an isolate pays ~15ms CPU once. A sentinel in scripts/check-patched-deps.ts guards against the patch silently not applying, since a revert would reproduce the incident with no functional signal.

Worth an upstream issue: the warm-up default is actively harmful for large-bundle workers; it should be opt-in.

Verify after deploy: requests/isolate back to ~5-7 and http.server p95 back under ~2.5s in the executor-cloud dataset.

@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Cloudflare preview

Torn down — the PR is closed.

@RhysSullivan
RhysSullivan marked this pull request as ready for review August 25, 2026 21:14
@RhysSullivan
RhysSullivan merged commit 05c3b22 into main Aug 25, 2026
40 of 42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant